// songplayer.cpp

// 2008-05-02  9:28:49 (Jake): created

#include "crankit_precompiled.h"

#include "song.h"
#include "songplayer.h"

using namespace std;

SongPlayer::SongPlayer()
{

}

void SongPlayer::load(const Song* song)
{
	{
		string file = song->getSongFile();
		osg::ref_ptr<openalpp::FileStream> fstream = new openalpp::FileStream(file);
		osg::ref_ptr<openalpp::Source> source = new openalpp::Source(fstream.get());
		source->setLooping(false);
		source->setPosition(-10, 0, 0);
		_songLeft = source.get();
		_songLeft->ref(); // TODO: temp hack
	}

	{
		string file = song->getGuitarFile();
		osg::ref_ptr<openalpp::FileStream> fstream = new openalpp::FileStream(file);
		osg::ref_ptr<openalpp::Source> source = new openalpp::Source(fstream.get());
		source->setLooping(false);
		source->setPosition(10, 0, 0);
		_guitarLeft = source.get();
		_guitarLeft->ref(); // TODO: temp hack
	}
}

void SongPlayer::play()
{
	_songLeft->play();
	_guitarLeft->play();
}

void SongPlayer::pause()
{
	_songLeft->pause();
	_guitarLeft->pause();
}

void SongPlayer::resume()
{

}

void SongPlayer::stop()
{
	_songLeft->stop();
	_guitarLeft->stop();
}

void SongPlayer::destroy()
{
	_songLeft = 0;
	_guitarLeft = 0;
}
